package com.kye.express.business.invoice_online.detail;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.jakewharton.rxbinding2.view.RxView;
import com.kye.base.DebounceObservableTransformer;
import com.kye.express.R;
import com.kye.express.business.waybill.waybill_detail.WayBillDetailActivity;
import com.kye.express.business.waybill_search.WaybillSearchActivity;
import com.kye.express.databinding.ItemInvoiceWaybillBinding;
import com.kye.model.bean.invoice_online.GetInvoiceDetailResultBean;

import io.reactivex.functions.Consumer;

class InvoiceWaybillltemViewBinder extends me.drakeet.multitype.ItemViewBinder<GetInvoiceDetailResultBean.WaybillNoDataBean, InvoiceWaybillltemViewBinder.ViewHolder> {

    private Context mContext;

    public InvoiceWaybillltemViewBinder(Context context) {
        mContext = context;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View view = inflater.inflate(R.layout.item_invoice_waybill, parent, false);
        return new ViewHolder(view);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull GetInvoiceDetailResultBean.WaybillNoDataBean item) {
        holder.bindData(item);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private GetInvoiceDetailResultBean.WaybillNoDataBean data;
        ItemInvoiceWaybillBinding dataBinding;

        public ViewHolder(View itemView) {
            super(itemView);
            dataBinding = DataBindingUtil.bind(itemView);
        }


        public void bindData(GetInvoiceDetailResultBean.WaybillNoDataBean item) {
            data = item;
            dataBinding.setData(item);
            dataBinding.tvPrice.setText("￥" + item.getInvoicedAmount());
            RxView.clicks(dataBinding.getRoot())
                    .compose(new DebounceObservableTransformer<>())
                    .subscribe(new Consumer<Object>() {
                        @Override
                        public void accept(Object o) throws Exception {
                            WayBillDetailActivity.startActivity(mContext,item.getWaybill());
                        }
                    });
        }
    }
}
